package studentinformationmanagementsystem.dao.impl;

import studentinformationmanagementsystem.dao.BaseDao;
import studentinformationmanagementsystem.dao.ClassandgradeDao;
import studentinformationmanagementsystem.entity.Classandgrade;
import studentinformationmanagementsystem.entity.Student;

import java.util.List;

/**
 * @author 苗庆
 * @version 1.0
 */
public class ClassandgradDaolmpl extends BaseDao implements ClassandgradeDao {

    /**
     * 对班级信息进行添加
     * @param classandgrade  班级对象
     * @return  受影响的记录行数
     */
    @Override
    public int insert(Classandgrade classandgrade) {
        String sql = "INSERT INTO `t_classandgrade` (`classandgrade`, `briefintroduction`, `qqGroup`, `teacherid`) VALUES (?, ?, ?, ?)";
        return super.update(sql,classandgrade.getClassandgrade(),classandgrade.getBriefintroduction(),classandgrade.getQqGroup(),classandgrade.getTeacherid());
    }


    /**
     *  根据ID更新班级信息
     * @param classandgrade  班级对象
     * @return 受影响的记录行数
     */
    @Override
    public int update(Classandgrade classandgrade) {
        String sql = "UPDATE `t_classandgrade` SET `classandgrade` = ? , `briefintroduction` = ? , `qqGroup` = ? , `teacherid` = ? WHERE `classandgradeid` = ? ";
        return super.update(sql,classandgrade.getClassandgrade(),classandgrade.getBriefintroduction(),classandgrade.getQqGroup(),classandgrade.getTeacherid(),classandgrade.getClassandgradeid());
    }

    /**
     *  根据ID删除班级
     * @param classandgrade 班级ID
     * @return 受影响的记录行数
     */
    @Override
    public int delete(Classandgrade classandgrade) {
        String sql = "DELETE FROM `t_classandgrade` WHERE `classandgradeid` = ?";
        return super.update(sql, classandgrade.getClassandgradeid());
    }

    /**
     * 查询所有班级信息
     * @return 所有班级信息
     */
    @Override
    public List<Classandgrade> queryAll() {
        String sql = "SELECT * FROM `t_classandgrade`";
        return super.queryForList(Classandgrade.class, sql);
    }

    /**
     * 根据班级ID查询班级信息
     * @param classandgrade 班级ID
     * @return 班级信息
     */
    @Override
    public Classandgrade queryById(Classandgrade classandgrade) {
        String sql = "SELECT * FROM `t_classandgrade` WHERE `classandgradeid` = ?";
        return super.queryForOne(Classandgrade.class, sql, classandgrade.getClassandgradeid());
    }


    /**
     * 根据班级名称查询班级信息
     * @param classandgrade 班级名称
     * @return 班级信息
     */
    @Override
    public Classandgrade queryByClassandgradeNname(Classandgrade classandgrade) {
        String sql = "SELECT * FROM `t_classandgrade` WHERE `classandgrade` = ?";
        return super.queryForOne(Classandgrade.class, sql, classandgrade.getClassandgrade());
    }


    /**
     * 查询总记录条数
     */
    @Override
    public Integer queryForPageTotalCount() {
        String sql = "SELECT COUNT(1) FROM `t_classandgrade`";
        Number count = (Number) queryForSingleValue(sql);
        return count.intValue();
    }


    /**
     * 分页查询DAO层方法
     *
     * @param begin    起始记录行数
     * @param pageSize 每页展示数量
     * @return
     */
    @Override
    public List<Classandgrade> queryForPageItems(int begin, int pageSize) {

        String sql = "SELECT * FROM `t_classandgrade` LIMIT ?, ?";
        return super.queryForList(Classandgrade.class, sql, begin, pageSize);


    }
}
